package com.meiqiongproperty.yiguanjia.ui.picker;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;

import com.meiqiongproperty.yiguanjia.R;

/**
 * @author Chen
 * @version V1.0
 * @Describe
 * @package com.sameway.cnotes.ui.picker
 * @date 17/3/30 下午1:59
 */
public class UploadPicDialog extends Dialog {
    private Params params;

    public UploadPicDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    public void setParams(Params params) {
        this.params = params;
    }

    public interface OnClickFinshListener {
        void onCameraPhotoClick();

        void onCameraClick();

        void onCancel();
    }

    private static final class Params {
        private boolean shadow = true;
        private boolean canCancel = true;
        private OnClickFinshListener callback;
    }

    public OnClickFinshListener callback;

    public static class Builder {
        private final Context context;
        private final UploadPicDialog.Params params;

        public Builder(Context context) {
            this.context = context;
            params = new UploadPicDialog.Params();
        }


        public Builder setOnClickCremera(OnClickFinshListener onDateSelectedListener) {
            params.callback = onDateSelectedListener;
            return this;
        }

        public UploadPicDialog crete() {
            final EditText rate_value;
            final UploadPicDialog dialog = new UploadPicDialog(context, params.shadow ? R.style.Theme_Light_NoTitle_Dialog : R.style.Theme_Light_NoTitle_NoShadow_Dialog);
            View view = LayoutInflater.from(context).inflate(R.layout.upload_pictures_dialog, null);
            rate_value = (EditText) view.findViewById(R.id.rate_value);
            view.findViewById(R.id.camera).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    dialog.dismiss();
                    params.callback.onCameraClick();
                }
            });
            view.findViewById(R.id.camera_phone).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    dialog.dismiss();
                    params.callback.onCameraPhotoClick();
                }
            });
            view.findViewById(R.id.camera_cancel).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    dialog.dismiss();
                    params.callback.onCancel();
                }
            });
            Window win = dialog.getWindow();
            win.getDecorView().setPadding(0, 0, 0, 0);
            WindowManager.LayoutParams lp = win.getAttributes();
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
            win.setAttributes(lp);
            win.setGravity(Gravity.BOTTOM);
            win.setWindowAnimations(R.style.Animation_Bottom_Rising);

            dialog.setContentView(view);
            dialog.setCanceledOnTouchOutside(params.canCancel);
            dialog.setCancelable(params.canCancel);
            dialog.setParams(params);
            return dialog;
        }
    }
}